package com.woniuxy.mesboot.service.impl;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.util.RandomUtil;
import com.woniuxy.mesboot.dto.InspectionRecordDTO;
import com.woniuxy.mesboot.mapper.InspectionRecordMapper;
import com.woniuxy.mesboot.service.InspectionRecordService;
import com.woniuxy.mesboot.vo.InspectionRecordVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author ：lisir
 * @date ：Created in 2023/5/25 16:53
 * @description：TODO
 */
@Service
public class InspectionRecordServiceImpl implements InspectionRecordService {

    @Resource
    private InspectionRecordMapper inspectionRecordMapper;

    @Override
    public int insertSelective(InspectionRecordDTO record) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        Date date = new Date();
        String dateStr = sdf.format(date);
        int i = RandomUtil.randomInt(1000,9999);
        dateStr = dateStr + i;
        record.setInspectionRecordCode(dateStr);
        DateTime dt = new DateTime();
        record.setInspectionRecordTime(dt);
        return inspectionRecordMapper.insertSelective(record);
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return inspectionRecordMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(InspectionRecordDTO record) {
        return inspectionRecordMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public InspectionRecordVO selectByPrimaryKey(Long id) {
        return inspectionRecordMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<InspectionRecordVO> selectAll(InspectionRecordDTO inspectionRecordDTO) {
        return inspectionRecordMapper.selectAll(inspectionRecordDTO);
    }
}
